<?php
$ch = curl_init();
$hashtags = "%23sebusca";
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.atom?q=$hashtags");
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_GET, 1);

$busqueda = curl_exec($ch);

$tweet = explode('<entry>',$busqueda);

for($i = 1; $i <= 19; $i += 1) {
	wtf($tweet[$i]);
}

function hacerclickeable($texto) {
	$texto = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1">\\1</a>', $texto);
	$texto = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2">\\2</a>', $texto);
	$texto = eregi_replace('((@)[-a-zA-Z0-9_]+)','<a href="http://twitter.com/\\1">\\1</a>', $texto);
	return $texto;
}

function wtf($tweet) 
{
	//echo "Tweet:<br/>$tweet<br />";

	$total = strlen($tweet);
	$delante = strpos($tweet,'<content type="html">') + 21;
	$detras = strpos($tweet,'</content>') - $delante;
	$texto = substr($tweet,$delante,$detras);
	echo "Texto:<br />$texto<br /><br />";
	
	//$texto = hacerclickeable($texto);
	
	//$delantenick = strpos($tweet,'"from_user":"') + 13;
	//$detrasnick = strpos($tweet,'","to_user_id"') - $total;
	//$nick = substr($tweet,$delantenick,$detrasnick);
	
	//echo "<a href=http://twitter.com/$nick>@$nick</a>: $texto <br />$tweet<br />";
}
?>
